﻿using B.S.BasicData.Api.Read.Application.Command.ShenPi;
using B.S.BasicData.Domian.Entities.shenpi;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.ShenPi
{
    public class DeptGetHandler : IRequestHandler<DeptGetCommand, ApiResult<List<DeptModel>>>
    {
        private readonly IBaseRepository<DeptModel> deptRepo;

        public DeptGetHandler(IBaseRepository<DeptModel>deptRepo)
        {
            this.deptRepo = deptRepo;
        }
        public Task<ApiResult<List<DeptModel>>> Handle(DeptGetCommand request, CancellationToken cancellationToken)
        {
           var res= new ApiResult<List<DeptModel>>();
            var dept = deptRepo.GetAll();
            res.Message = "查询成功";
            res.Code = ApiEnum.Ok;
            res.Data=dept.ToList();
            return Task.FromResult(res);
        }
    }
}
